package com.admin.discountService.service.impl;

import com.admin.discountService.pojo.MobileEndDiscount;
import com.admin.discountService.mapper.MobileEndDiscountMapper;
import com.admin.discountService.service.MobileEndDiscountService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 折扣表 服务实现类
 * </p>
 *
 * @author wang-chao-wen
 * @since 2022-12-13
 */
@Service
public class MobileEndDiscountServiceImpl extends ServiceImpl<MobileEndDiscountMapper, MobileEndDiscount> implements MobileEndDiscountService {
@Autowired
private MobileEndDiscountMapper mobileEndDiscountMapper;
    @Override
    // 秒 分 时 天 月 周
    @Scheduled(cron = "*/10 * * * * *")
    public void scheduledUpdateStatus() {
        List<MobileEndDiscount> discountList = mobileEndDiscountMapper.selectList(null);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        QueryWrapper<MobileEndDiscount> queryWrapper = new QueryWrapper<>();
        for(MobileEndDiscount mobileEndDiscount : discountList){
            long time = mobileEndDiscount.getExpirationDate().getTime();
             Date date = new Date();
            long currentTime = date.getTime();
            if(currentTime > time){
                int count = mobileEndDiscountMapper.updateStatus(dateFormat.format(mobileEndDiscount.getExpirationDate()));
            }
        }
    }
}
